﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using System.IO;

namespace Order.MicroService.Api.Config
{
    public class SwaggerConfig
    {
        public static void Register(IServiceCollection services)
        {
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title = "Order.MicroService.Api",
                    Version = "v1"
                });
                //文档注释xml
                var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
                var xmlPath = Path.Combine(basePath, "ApiSwagger.xml");//此处更改你的xml文档名字
                c.IncludeXmlComments(xmlPath, true);
                //实体类注释XML  由于Api层引用了Model层的ModelSwagger.xml，所以这里获取的还是basePath
                //下边可以直接写成
                //var modelPath = Path.GetDirectoryName(typeof(Orders).Assembly.Location);
                //var xmlModelPath = Path.Combine(modelPath, "ModelSwagger.xml");
                var xmlModelPath = Path.Combine(basePath, "ModelSwagger.xml");
                var xmlViewModelPath = Path.Combine(basePath, "ViewModelSwagger.xml");
                //第二个参数true表示注释文件包含了控制器的注释
                c.IncludeXmlComments(xmlModelPath, true);
                c.IncludeXmlComments(xmlViewModelPath, true);
            });
        }
    }
}
